package com.demo.common;

import java.util.Random;

/**
 * Created by 宋冲 on 2014/6/18.
 * 高德软件
 */
public class Test {
    public static void main(String[] args) {
        Long a = 1L;
        Long b = 2L;
        for (int i = 0; i < 5; i++) {
            new MyThread(a).start();
        }

        for (int i = 0; i < 5; i++) {
            new MyThread(b).start();
        }
    }

    public static void ttt(Long a) throws Exception {
        synchronized (a){
            int b = new Random().nextInt();
            System.out.println(a + ">>>>" + b);
            Thread.sleep(1000);
            System.out.println(a + ">>>>" + b);
        }
    }

    static class MyThread extends Thread{
        Long a;
        public MyThread(Long a){
            this.a = a;
        }
        @Override
        public void run() {
            try {
                ttt(a);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
